<template>
  <div class="pdf-box" @click="downloadPdf(pdfData.id)" >
    <div class="head-box">
      <div class="head-left">
        <img src="../assets/img/pdf.svg" alt="" width="50" height="60" />
      </div>
      <div class="head-right">
        <div class="head-right-top">
          {{ pdfData.direction }}
          <span @click="(e) => downPDF(pdfData.id, e)" class="head-right-download"
            >点击下载</span
          >
          <span class="head-right-download">{{
            parseFloat(pdfData.size).toFixed(2) + "M"
          }}</span>
        </div>
        <div class="head-right-bottom">
          <div>预览：{{ pdfData.seeNum }}</div>
          <div>下载：{{ pdfData.uploadNum }}</div>
        </div>
      </div>
    </div>
    <div class="footer-box">
      <div>
        {{ pdfData.name }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from "vue";
import $axios from "@/http";
import { baseURL } from "@/http";
const { pdfData: pdfData } = defineProps({
  pdfData: {
    type: Object,
    default: () => ({}),
  },
  showDelPDF: {
    type: Boolean,
    default: false,
  },
});
const downloadPdf = (id: number) => {
  let aTag: HTMLAnchorElement | null = document.createElement("a");
  aTag.href = pdfData.pdf;
  aTag.target = "_blank";
  aTag.click();
  aTag = null;
  $axios
    .get("/pdf/addGoodNum", {
      params: {
        id,
      },
    })
    .then((res) => {
      //res.data.error === -1 && $parent.$parent.$parent.searchFile();
    });
};
const downPDF = (id: number, e:MouseEvent) => {
  e.stopPropagation()
  let aTag: HTMLAnchorElement | null = document.createElement("a");
  aTag.href = baseURL + "/pdf/download?id=" + id;
  aTag.click();
  aTag = null;
  $axios
    .get("/pdf/adduploadNum", {
      params: {
        id,
      },
    })
    .then((res) => {
      //res.data.error === -1 && $parent.$parent.$parent.searchFile();
    });
};
</script>

<style lang="scss" scoped>
@keyframes bound {
  0% {
    transform: rotate(15deg);
  }
  100% {
    transform: rotate(-15deg);
  }
}
.pdf-box {
  border-radius: 5px;
  width: 250px;
  height: 120px;
  background-color: rgba(0, 0, 0, 0.1);
  color: #333;
  margin: 8px;
  position: relative;
  transition: all 0.3s;
  &:hover {
    transform: scale(1.05);
  }
  .delPDF {
    width: 23px;
    height: 23px;
    border-radius: 5px;
    background-color: red;
    color: #fff;
    text-align: center;
    line-height: 23px;
    font-size: 1000;
    position: absolute;
    z-index: 9;
    right: 0;
    top: 0;
    transform: rotate(15deg);
    animation: bound linear 0.1s infinite alternate-reverse;
    cursor: pointer;
  }
  .head-box {
    padding: 7px;
    display: flex;
    width: 200px;
    // background-color: rgba(0, 0, 0, 0.05);
    .head-left {
      font-size: 0px;
      margin-right: 5px;
    }
    .head-right {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .head-right-top {
        margin-top: 4px;
        text-align: left;
        font-size: 19px;
      }
      .head-right-download {
        font-size: 13px;
        color: rgba(0, 0, 0, 0.3);
        margin-left: 8px;
        vertical-align: middle;
        transition: color 0.2s;

        &:nth-child(1) {
          &:hover {
            color: #000;
          }
        }
      }
      .head-right-bottom {
        display: flex;
        color: rgba(0, 0, 0, 0.3);
        font-size: 13px;
        div {
          margin-right: 8px;
        }
      }
    }
  }
  .footer-box {
    text-align: center;
    padding: 3px;
    font-size: 13px;
  }
}
</style>
